import axios from 'axios'

// 创建 axios 实例
const service = axios.create({
    baseURL: 'https://bk.loval.ink/index.php?s=',
    timeout: 25 * 1000,
    headers: {
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
    }
})

// 请求拦截器
service.interceptors.request.use(config => {
    // config.headers['Content-Type'] = 'application/json;charset=utf-8'
    return config
})

// 响应拦截器
service.interceptors.response.use(response => {
    const result = response.data

    // 服务端返回错误
    if ( result.status === 500 ) {
        return Promise.reject(result)
    }

    // 服务端返回未登录
    if ( result.status === 401 ) {
        return Promise.reject(result)
    }

    // 返回结果
    return result
}, error => {
    return Promise.reject(error)
})

export default service
